package com.rv.common.core.domain;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author sundez
 * @version 1.1.3.7
 * @since 2025/6/17
 */
@Data
@NoArgsConstructor
public class R<T> implements Serializable {

    private static final long serialVersionUID = 1L;


    /**
     * 消息状态码
     */
    private int code = 0;

    /**
     * 消息内容
     */
    private String msg;

    /**
     * 数据对象
     */
    private T data;


    public static <T> R<T> ok() {
        return getR(null ,0 , "");
    }


    public static <T> R<T> ok(T data) {
        return getR(data ,0 , "");
    }

    public static <T> R<T> error(String msg) {
        return getR(null , -1 , msg);
    }

    private static <T> R<T> getR(T data, int code, String msg) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setData(data);
        r.setMsg(msg);
        return r;
    }
}
